<template>
  <div>
    <!--面包屑导航-->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item>用户界面</el-breadcrumb-item>
      <el-breadcrumb-item>订单</el-breadcrumb-item>
    </el-breadcrumb>

    <el-card>
      <!--搜索区域-->
      <el-row :gutter="20">
        <el-col :span="7">
          <el-input placeholder="请输入订单号" v-model="queone.o_number">
            <el-button
              slot="append"
              icon="el-icon-search"
              @click="getonemess"
            ></el-button>
          </el-input>
        </el-col>
        <el-col :span="4">
          <el-button type="primary" @click="addDialog = true"
            >添加订单</el-button
          >
        </el-col>
      </el-row>

      <el-table :data="o_messagedata" border stripe class="table-box1">
        <el-table-column type="index"></el-table-column>
        <el-table-column label="订单号" prop="Onumber"></el-table-column>
        <el-table-column label="账号" prop="Ccode"></el-table-column>
        <el-table-column label="运费" prop="Ofreight"></el-table-column>
        <el-table-column label="总费用" prop="Ototal"></el-table-column>
        <el-table-column label="运输注意" prop="Otranrequir"></el-table-column>
        <el-table-column label="能否供货" prop="Osupply"></el-table-column>
        <el-table-column label="总重量" prop="Oweight"></el-table-column>
        <el-table-column
          label="提交订单日期"
          prop="Odataorder"
        ></el-table-column>
        <el-table-column label="运输日期" prop="Odatatran"></el-table-column>
        <el-table-column label="操作" prop="">
          <template>
            <el-tooltip effect="dark" content="修改" placement="top">
              <el-button
                type="primary"
                icon="el-icon-edit"
                size="mini"
                @click="showmod"
              ></el-button>
            </el-tooltip>
            <el-tooltip effect="dark" content="删除" placement="top">
              <el-button
                type="danger"
                icon="el-icon-delete"
                size="mini"
                @click="showdel"
              ></el-button>
            </el-tooltip>
          </template>
        </el-table-column>
      </el-table>
    </el-card>

    <span>查询区↓</span>
    <el-card>
      <el-table :data="onemess" border stripe class="table-box1">
        <el-table-column label="订单号" prop="Onumber"></el-table-column>
        <el-table-column label="账号" prop="Ccode"></el-table-column>
        <el-table-column label="运费" prop="Ofreight"></el-table-column>
        <el-table-column label="总费用" prop="Ototal"></el-table-column>
        <el-table-column label="运输注意" prop="Otranrequir"></el-table-column>
        <el-table-column label="能否供货" prop="Osupply"></el-table-column>
        <el-table-column label="总重量" prop="Oweight"></el-table-column>
        <el-table-column
          label="提交订单日期"
          prop="Odataorder"
        ></el-table-column>
        <el-table-column label="运输日期" prop="Odatatran"></el-table-column>
      </el-table>
    </el-card>

    <el-dialog
      title="添加订单"
      :visible.sync="addDialog"
      width="50%"
      @close="Tclose"
    >
      <!--内容主体区域-->
      <el-form
        :model="addForm"
        :rules="addFormrules"
        ref="addFormRef"
        label-width="70px"
      >
        <el-form-item label="订单号" prop="Vnumber">
          <el-input v-model="addForm.Vnumber"></el-input>
        </el-form-item>
        <el-form-item label="帐号" prop="Vcode">
          <el-input v-model="addForm.Vcode"></el-input>
        </el-form-item>
        <el-form-item label="日期" prop="Vdataorder">
          <el-input v-model="addForm.Vdataorder"></el-input>
        </el-form-item>
      </el-form>
      <!--底部区域-->
      <span slot="footer" class="dialog-footer">
        <el-button @click="addDialog = false">取 消</el-button>
        <el-button type="primary" @click="addorder">确 定</el-button>
      </span>
    </el-dialog>

    
    
    <el-dialog
      title="删除订单"
      :visible.sync="delDialog"
      width="50%"
      @close="Dclose"
    >
      <!--内容主体区域-->
      <el-form
        :model="delForm"
        :rules="delFormrules"
        ref="delFormRef"
        label-width="150px"
      >
        <el-form-item label="订单号" prop="Dnumber">
          <el-input v-model="delForm.Dnumber"></el-input>
        </el-form-item>
      </el-form>
      <!--底部区域-->
      <span slot="footer" class="dialog-footer">
        <el-button @click="delDialog = false">取 消</el-button>
        <el-button type="primary" @click="delorder">确 定</el-button>
      </span>
    </el-dialog>






    <el-dialog
      title="修改订单"
      :visible.sync="editDialogVisible"
      width="50%"
      @close="Eclose"
    >
      <!--内容主体区域-->
      <el-form
        :model="editForm"
        :rules="editFormrules"
        ref="editFormRef"
        label-width="150px"
      >
        <el-form-item label="输入要修改的订单号" prop="Enumber">
          <el-input v-model="editForm.Enumber"></el-input>
        </el-form-item>
        <el-form-item label="输入帐号" prop="Ecode">
          <el-input v-model="editForm.Ecode"></el-input>
        </el-form-item>
        <el-form-item label="输入运费" prop="Efreight">
          <el-input v-model="editForm.Efreight"></el-input>
        </el-form-item>
        <el-form-item label="输入总费用" prop="Etotal">
          <el-input v-model="editForm.Etotal"></el-input>
        </el-form-item>
        <el-form-item label="输入运输注意" prop="Etranrequir">
          <el-input v-model="editForm.Etranrequir"></el-input>
        </el-form-item>
        <el-form-item label="输入能否供货" prop="Esupply">
          <el-input v-model="editForm.Esupply"></el-input>
        </el-form-item>
        <el-form-item label="输入总重量" prop="Eweight">
          <el-input v-model="editForm.Eweight"></el-input>
        </el-form-item>
        <el-form-item label="输入订单日期" prop="Edataorder">
          <el-input v-model="editForm.Edataorder"></el-input>
        </el-form-item>
        <el-form-item label="输入运输日期" prop="Edatatran">
          <el-input v-model="editForm.Edatatran"></el-input>
        </el-form-item>
      </el-form>
      <!--底部区域-->
      <span slot="footer" class="dialog-footer">
        <el-button @click="editDialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="editorder">确 定</el-button
        >
      </span>
    </el-dialog>
  </div>
</template>

<script>
export default {
  data() {
    return {
      query: "",
      o_messagedata: [],
      queone: {
        o_number: "",
      },
      onemess: [],
      addDialog: false,
      //添加订单所用的数据
      addForm: {
        Vnumber: "",
        Vcode: "",
        Vdataorder: "",
      },
      addFormrules: {
        Vnumber: [
          {
            required: true,
            message: "请输入订单号",
            trigger: "blur",
          },
        ],
        Vcode: [
          {
            required: true,
            message: "请输入帐号",
            trigger: "blur",
          },
        ],
        Vdataorder: [
          {
            required: true,
            message: "请输入提交订单的日期",
            trigger: "blur",
          },
        ],
      },
      //修改框显示
      editDialogVisible: false,

      //修改所需属性
      editForm: {
        Enumber: "",
        Ecode: "",
        Efreight: "",
        Etotal: "",
        Etranrequir: "",
        Esupply: "",
        Eweight: "",
        Edataorder: "",
        Edatatran: "",
      },

      editFormrules: {
        Enumber: [
          {
            required: true,
            message: "请输入订单号",
            trigger: "blur",
          },
        ],
        Ecode: [
          {
            required: true,
            message: "请输入帐号",
            trigger: "blur",
          },
        ],
        Esupply: [
          {
            required: true,
            message: "请输入是否能供货",
            trigger: "blur",
          },
        ],
      },


      //
      delDialog: false,

      delForm:{
          Dnumber: "",
      },

      delFormrules: {
        Dnumber: [
          {
            required: true,
            message: "请输入订单号",
            trigger: "blur",
          },
        ],
      },

    };
  },
  created() {
    this.geto_messagedata();
  },
  methods: {
    async geto_messagedata() {
      const { data: res } = await this.$http.post("Data/apis/o_messageget", {
        params: this.query,
      });
      this.o_messagedata = res;
      console.log(res);
    },

    async getonemess() {
      const { data: dsn } = await this.$http.post("Data/apis/o_messagegetone", {
        params: this.queone.o_number,
      });
      console.log(dsn);
      this.onemess = dsn.o_messagedata;
      console.log(this.onemess);
      if (dsn.o_messagedata.length == 1) {
        this.$message.success("查找成功");
      }
    },

    Tclose() {
      this.$refs.addFormRef.resetFields();
    },

    addorder() {
      this.$refs.addFormRef.validate(async (valid) => {
        if (!valid) return;

        const { data: vsn } = await this.$http.post(
          "Data/apis/o_messageadd",
          this.addForm
        );

        if (vsn.code == 200) {
          this.$message.success("添加成功");
          this.addDialog = false;
          this.geto_messagedata();
        }
      });
    },

    showmod() {
      this.editDialogVisible = true;
    },

    Eclose() {
      this.$refs.editFormRef.resetFields();
    },

    editorder() {
      this.$refs.editFormRef.validate(async (valid) => {
        if (!valid) return;

        const { data: psn } = await this.$http.post(
          "Data/apis/o_messageput",
          this.editForm
        );

        if (psn.code == 200) {
          this.$message.success("修改成功");
          this.editDialogVisible = false;
          this.geto_messagedata();
        }
      });
    },

    Dclose() {
      this.$refs.delFormRef.resetFields();
    },

    showdel() {
        this.delDialog = true;
    },

    delorder() {
        this.$refs.delFormRef.validate(async (valid) => {
        if (!valid) return;

        const { data: gsn } = await this.$http.post(
          "Data/apis/o_messagedel",
          this.delForm
        );

        if (gsn.code == 200) {
          this.$message.success("删除成功");
          this.delDialog = false;
          this.geto_messagedata();
        }
      });
    }

  },
};
</script>

<style>
.table-box1 {
  margin-top: 15px;
  font-size: 12px;
}
</style>